package leetcode;

import javax.swing.tree.TreeNode;

public class Solution12 {
    public int sumOfLeftLeaves(TreeNode root) {
        //判断为空的情况
        if(root == null){
            return 0;
        }
        if(root.left == null && root.right == null){
            return 0;
        }
        //使用后续遍历 左右中
        int leftNum = sumOfLeftLeaves(root.left);
        int rightNum = sumOfLeftLeaves(root.right);
        int midval = 0;
        if(root.left != null && root.left.left == null && root.left.right ==null){
            midval = root.left.val;
        }

        return midval + leftNum + rightNum;
    }
}
